package com.java110.mall.cart.bmo.report.impl;

import com.java110.mall.cart.bmo.report.IMallReport;
import com.java110.dto.mallReport.MallReportDto;
import com.java110.dto.mallReport.SellingCostDto;
import com.java110.intf.cart.IStoreStatisticsInnerServiceSMO;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MallReportImpl implements IMallReport {

    @Autowired
    private IStoreStatisticsInnerServiceSMO storeStatisticsInnerServiceSMOImpl;

    @Override
    public ResponseEntity<String> getInStockInfo(MallReportDto mallIndexDto) {
        int count = storeStatisticsInnerServiceSMOImpl.getInStockInfoCount(mallIndexDto);
        List<MallReportDto> inoutOrderProductDtos = null;
        if (count > 0) {
            inoutOrderProductDtos =  storeStatisticsInnerServiceSMOImpl.getInStockInfo(mallIndexDto);
        } else {
            inoutOrderProductDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) mallIndexDto.getRow()), count, inoutOrderProductDtos);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
    @Override
    public ResponseEntity<String> getSalesInfo(MallReportDto mallIndexDto) {
        int count = storeStatisticsInnerServiceSMOImpl.getSalesInfoCount(mallIndexDto);
        List<MallReportDto> inoutOrderProductDtos = null;
        if (count > 0) {
            inoutOrderProductDtos =  storeStatisticsInnerServiceSMOImpl.getSalesInfo(mallIndexDto);
        } else {
            inoutOrderProductDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) mallIndexDto.getRow()), count, inoutOrderProductDtos);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }

    @Override
    public ResponseEntity<String> getInoutInfo(MallReportDto mallIndexDto) {
        int count = storeStatisticsInnerServiceSMOImpl.getInoutInfoCount(mallIndexDto);
        List<MallReportDto> inoutOrderProductDtos = null;
        if (count > 0) {
            inoutOrderProductDtos =  storeStatisticsInnerServiceSMOImpl.getInoutInfo(mallIndexDto);
        } else {
            inoutOrderProductDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) mallIndexDto.getRow()), count, inoutOrderProductDtos);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }

    @Override
    public ResponseEntity<String> getSalesRankingInfo(MallReportDto mallIndexDto) {
        int count = storeStatisticsInnerServiceSMOImpl.getSalesRankingInfoCount(mallIndexDto);
        List<MallReportDto> inoutOrderProductDtos = null;
        if (count > 0) {
            inoutOrderProductDtos =  storeStatisticsInnerServiceSMOImpl.getSalesRankingInfo(mallIndexDto);
        } else {
            inoutOrderProductDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) mallIndexDto.getRow()), count, inoutOrderProductDtos);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }

    @Override
    public ResponseEntity<String> getSellingCost(SellingCostDto sellingCostDto) {
        int count = storeStatisticsInnerServiceSMOImpl.getSellingCostCount(sellingCostDto);
        List<SellingCostDto> sellingCostDtos = null;
        if (count > 0) {
            sellingCostDtos =  storeStatisticsInnerServiceSMOImpl.getSellingCost(sellingCostDto);
        } else {
            sellingCostDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) sellingCostDto.getRow()), count, sellingCostDtos);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }
    @Override
    public ResponseEntity<String> getSellingCostDetail(SellingCostDto sellingCostDto) {
        int count = storeStatisticsInnerServiceSMOImpl.getSellingCostDetailCount(sellingCostDto);
        List<SellingCostDto> sellingCostDtos = null;
        if (count > 0) {
            sellingCostDtos =  storeStatisticsInnerServiceSMOImpl.getSellingCostDetail(sellingCostDto);
        } else {
            sellingCostDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) sellingCostDto.getRow()), count, sellingCostDtos);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        return responseEntity;
    }

}
